package com.freewater.library.lending.reader.presentation;


import com.freewater.library.lending.reader.application.ReaderCommandService;
import com.freewater.library.lending.reader.presentation.request.CreateReaderRequest;
import com.freewater.library.lending.reader.presentation.request.DisableReaderRequest;
import com.freewater.library.lending.reader.presentation.request.EnableReaderRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/reader")
@RequiredArgsConstructor
@Validated
public class ReaderController {

    private final ReaderCommandService readerCommandService;

    @PostMapping("/create")
    public void create(@Validated @RequestBody CreateReaderRequest request) {
        this.readerCommandService.createReader(request.getName());
    }

    @PostMapping("/enable")
    public void enable(@Validated @RequestBody EnableReaderRequest request) {
        this.readerCommandService.enableReader(request.getId());
    }

    @PostMapping("/disable")
    public void disable(@Validated @RequestBody DisableReaderRequest request) {
        this.readerCommandService.disableReader(request.getId());
    }
}
